package com.ruoyi.api.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.api.dto.equipment.resp.EquipmentMapStatisticsRespDto;
import com.ruoyi.api.dto.equipment.resp.EquipmentRealTimeStatisticsRespDto;
import com.ruoyi.api.dto.equipment.resp.EquipmentStatisticsRespDto;
import com.ruoyi.api.service.EquipmentStatService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.stat.equipment.service.IEquipmentStatService;

import lombok.RequiredArgsConstructor;

/**
 * 车辆和设备统计数据汇总
 *
 * @author cc
 * @date 2023-04-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/stat/equipment")
public class EquipmentStatController extends BaseController {

    private final IEquipmentStatService iEquipmentStatService;
    private final EquipmentStatService equipmentStatService;
    
	/**
	 * 车辆统计数据汇总
	 * <p>
	 * 年（最近一年），月（最近一个月），季（最近3个月），周（最近7天） ，默认年
	 * 
	 * @param type year 年 quarter 季度 month 月 week 周
	 * @return 车辆统计数据 resp
	 */
	@GetMapping("/equipmentStatistics")
	public R<EquipmentStatisticsRespDto> getEquipmentStatistics(
			@RequestParam(name = "type", defaultValue = "year") String type) {
		return R.ok(equipmentStatService.getEquipmentStatistics(type));
	}

	/**
	 * 车辆实时数据
	 * 
	 * @param date 查询日期，格式 2013-04-30 , 默认 当天
	 * @return 车辆统计实时数据 resp
	 */
	@GetMapping("/equipmentRealTimeStatistics")
	public R<EquipmentRealTimeStatisticsRespDto> getEquipmentRealTimeStatistics(
			@RequestParam(name = "date", defaultValue = "") String date) {
		return R.ok(equipmentStatService.getEquipmentRealTimeStatistics(date));
	}

	/**
	 * 车辆实时明细数据 -> 地图上面的车辆实时数据
	 * @param serviceTypeId 服务类型id
	 * @param date 查询时间，格式 2013-03-11 , 默认 当天
	 * @return 车辆实时明细数据 resp
	 */
	@GetMapping("/equipmentMapStatistics")
	public R<EquipmentMapStatisticsRespDto> getEquipmentMapStatistics(
			@RequestParam(name = "serviceTypeId") Integer serviceTypeId,
			@RequestParam(name = "date", defaultValue = "") String date) {
		return R.ok(equipmentStatService.getEquipmentMapStatistics(serviceTypeId, date));
	}
    
    
    @GetMapping("/createData")
	public R<Void> createData(@RequestParam(name="queryTime" , defaultValue = "") String queryTime) {
		return toAjax(this.iEquipmentStatService.createStatData(queryTime));
	}
}
